﻿using Dm.util;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataCollection.Core.Models
{
    /// <summary>
    /// 数据库
    ///</summary>
    [SugarTable("c_history")]
    public class HistoryModel
    {
        #region 属性
        /// <summary>
        /// 备  注:编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "number", IsPrimaryKey = true)]
        public long Number { get; set; }

        /// <summary>
        /// 备  注:项目编号
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "project_number")]
        public long ProjectNumber { get; set; }

        /// <summary>
        /// 备  注:项目名称
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "project_name")]
        public string ProjectName { get; set; } = null!;

        /// <summary>
        /// 备  注:开始时间
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "start_time")]
        public long StartTime { get; set; }

        /// <summary>
        /// 备  注:结束时间
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "end_time")]
        public long EndTime { get; set; }

        /// <summary>
        /// 备  注:累计时间
        /// 默认值:
        ///</summary>
        [SugarColumn(ColumnName = "total_time")]
        public long TotalTime { get; set; }
        #endregion

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public int Add()
        {
            List<HistoryModel> list = new List<HistoryModel>();
            list.Add(this);
            int res = SqlSugarHelper.Insertable<HistoryModel>(list);
            return res;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public int Delete()
        {
            List<HistoryModel> list = new List<HistoryModel>();
            list.Add(this);
            int res = SqlSugarHelper.Deleteable<HistoryModel>(list);
            return res;
        }

        /// <summary>
        /// 更新
        /// </summary>
        /// <returns></returns>
        public int Update()
        {
            List<HistoryModel> list = new List<HistoryModel>();
            list.Add(this);
            int res = SqlSugarHelper.Updateable<HistoryModel>(list);
            return res;
        }

        /// <summary>
        /// 列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>

        public static List<HistoryModel> List(Dictionary<string, object> where)
        {

            return SqlSugarHelper.Inquireable<HistoryModel>(where);
        }

        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>

        public static List<HistoryModel> ListPage(Dictionary<string, object> where, int page, int pageSize, ref int totalCount)
        {
            return SqlSugarHelper.InquireableToPageList<HistoryModel>(where, page, pageSize, ref totalCount);
        }
    }
}
